<template>
	<view v-if="proId" :style="{ '--color': vuex_config.themeColor1, '--price': vuex_config.price }">
		<!-- 信息 -->
		<view class="video-info" v-if="dataForm.pk_id">
			<view class="video-title">{{ dataForm.name }}</view>
			<view class="video-desc">
				<view>{{ dataForm.date_creation | formTime }}</view>
				<view v-if="vuex_config.reading_volume == 1 && dataForm.view > 0">阅读量：{{ dataForm.view }}</view>
			</view>
		</view>
		<article-detail ref='article_view' :articleId="proId" @loadFinshed="loadFinshed"></article-detail>
		<template v-if="dataForm.pk_id && !dataForm.needBuy">
			<template v-if="dataList[0]">
				<view class="comment-title">
					<view class="ct-box">
						<view class="line"></view>
						<text>全部评论</text>
						<view class="line"></view>
					</view>
				</view>

				<view class="comment-box">
					<view class="cb-item" v-for="(item, index) in dataList" :key="index">
						<image class="cbi-img" :src="item.headimgurl"></image>
						<view class="cbi-right">
							<text>{{ item.nickname }}</text>
							<text class="r-ft">{{ item.content }}</text>
							<view class="r-time">
								<text>{{ item.date_creation | formTime }}</text>
							</view>
						</view>
					</view>
				</view>
			</template>
			<template v-if="dataForm.mode != 6 && vuex_config.comment == 1">
				<view style="height: 150rpx;"></view>
				<view class="footer">
					<view class="footer-item">
						<image src="../static/pl_edit.png" class="footer-img"></image>
						<input type="text" v-model="inputValue" class="foot-ipt" placeholder="亲, 说两句"
							@confirm="onInputConfirm" />
					</view>
					<view class="footer-send" @click="onInputConfirm">发送</view>
				</view>
			</template>
		</template>
		<sww-login></sww-login>
	
		
	</view>
</template>

<script>
	import articleDetail from '@/pagecomponents/articleDetail/index.vue';
	import {
		formatDate
	} from '@/utils/moment/index.js';
	import {
		pageShare
	} from '@/mixins/pageShare';
	import {
		pagingMixin
	} from '@/mixins/pagingMixin';
	import {
		mapActions
	} from 'vuex'
	export default {
		mixins: [pageShare, pagingMixin],
		components: {
			'article-detail': articleDetail
		},
		data() {
			return {
				dataForm: {},
				inputValue: '',
				proId: '',
				init:false
			};
		},
		onShow () {
			if(this.init){
				this.$refs.article_view.initData()
			}else{
				this.init = true
			}
		},
		onLoad(options) {
			this.proId = Number(options.id);
			this.onShareByH5();
		},
		filters: {
			formTime(time) {
				return formatDate(time, 'YYYY-MM-DD HH:mm:ss');
			}
		},
		onShareAppMessage: function() {
			return this.getShareAppMessage();
		},
		onShareTimeline: function() {
			return this.getShareTimeline();
		},
		onReachBottom() {
			if (this.vuex_config.comment == 1) {
				this._load_data();
			}
		},
		methods: {
			...mapActions(['loadUserCount']),
			loadFinshed(item) {
				this.dataForm = {
					...item
				};
				if (this.vuex_config.comment == 1 && !item.needBuy) {
					this.productComment();
				}
				this.customShareParams();
			},

			// 查询评论列表
			productComment() {
				this._init_data('GetProductComment', {
					product_id: this.proId,
					business_id: this.dataForm.fk_business_id
				}, {
					showLoading: false
				});
			},
			customShareParams() {
				if (!this.shareParams.title) {
					this.shareParams = {
						...this.shareParams,
						title: this.dataForm.name,
						imgUrl: this.dataForm.logo || ''
					};
					this.onShareByH5().then(() => {});
				}
			},

			// 发表评论
			onInputConfirm() {
				if (!this.inputValue) {
					return this.$toast('评论内容不能为空')
				}
				this.$login('onInputConfirm').then(res => {
					let params = {
						type: 10,
						product_id: this.dataForm.pk_id,
						content: this.inputValue,
						status: 1,
						business_id: this.dataForm.fk_business_id
					};
					this.$resPost('SetProductComment', {
							...params
						})
						.then(res => {
							this.$toast('评论成功');
							this.dataList.splice(0, 0, {
								headimgurl: this.vuex_user.headimgurl,
								content: this.inputValue,
								date_creation: new Date(),
								nickname: this.vuex_user.nickname
							});
							this.inputValue = '';
						})
						.catch(() => {
							this.$toast('评论失败');
						});
				});
			}
		}
	};
</script>
<style>
	page {
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>

	.video-info {
		width: 100%;
		padding: 0 24rpx;

		.video-title {
			text-align: center;
			font-size: 36rpx;
			font-weight: bold;
			padding: 10rpx 0;
		}

		.video-desc {
			font-size: 28rpx;
			color: #999999;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx 0 20rpx;
		}
	}

	.footer {
		display: flex;
		align-items: center;
		position: fixed;
		bottom: 0;
		width: 100%;
		height: calc(env(safe-area-inset-bottom) + 90rpx);
		display: flex;
		background-color: #fff;
		align-items: center;
		border-top: 1px solid #f1f1f1;
		padding: 0 26rpx env(safe-area-inset-bottom);

		/deep/.u-search {
			width: 700rpx;
		}

		.footer-item {
			display: flex;
			align-items: center;
			padding: 0 24rpx;
			flex: 1;
			height: 66rpx;
			background: #f3f3f3;
			border-radius: 33rpx;
		}

		.footer-img {
			width: 30rpx;
			height: 30rpx;
		}

		.foot-ipt {
			width: 100%;
			height: 100%;
			padding: 0 13rpx;
			background-color: #f5f5f5;
		}

		.footer-send {
			width: 100rpx;
			text-align: center;
			padding: 10rpx 5rpx;
			background-color: #f5f5f5;
			color: #666;
			margin-left: 20rpx;
		}
	}

	.comment-title {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		margin: 40rpx 0;

		.ct-box {
			display: flex;
			align-items: center;
			font-size: 34rpx;
			font-weight: bold;
			color: #333;

			.line {
				width: 56rpx;
				height: 2rpx;
				background-color: #d6d6d6;
				margin: 0 20rpx;
			}
		}
	}

	.comment-box {
		padding: 0 24rpx;

		.cb-item {
			display: flex;
			margin-bottom: 40rpx;

			.cbi-img {
				width: 60rpx;
				height: 60rpx;
				border-radius: 50%;
				margin-right: 16rpx;
			}

			.cbi-right {
				display: flex;
				flex-direction: column;
				font-size: 26rpx;
				color: #333;
				width: 90%;

				.r-ft {
					font-size: 30rpx;
					color: #333;
					padding: 16rpx 0 24rpx;
				}

				.r-time {
					display: flex;
					align-items: center;
					font-size: 26rpx;
					color: #a9a9a9;

					.rt-btn {
						width: 78rpx;
						height: 40rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						background-color: #e5e5e5;
						font-size: 22rpx;
						color: #999;
						border-radius: 20rpx;
						margin-left: 20rpx;
					}
				}
			}
		}
	}

	.glo_bot_fix {
		background-color: var(--color);
	}
</style>
